//
//  MyConversation.m
//  parent
//
//  Created by 闫珍 on 15/9/11.
//  Copyright (c) 2015年 ci123. All rights reserved.
//

#import "MyConversation.h"
#import "JsonUtil.h"
#import "SBJson.h"
#import "Tool.h"

@implementation MyConversation

-(void)loadInfoByUsername
{
    if(self.conversation.conversationType == eConversationTypeChat){
//        NSString * url = [NSString stringWithFormat:@"%@%@/uid/%@",SERVER_URL_NEW,kMyInfomartion,self.conversation.chatter];
//        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]
//                                         options:NSDataReadingMappedIfSafe
//                                           error:nil];
//        if (data) {
//            NSDictionary *userInfoDic = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
//            NSDictionary *infoDic = [userInfoDic objectForKey:@"result"];
            NSDictionary *infoDic = [Tool getInfoById:self.conversation.chatter];
        
            _nickname = [infoDic objectForKey:@"nickname"];
            if(![[infoDic objectForKey:@"pic"] isEqual:[NSNull null]]){
                _pic = [infoDic objectForKey:@"pic"];
            }else{
                _pic = @"";
            }
            _city = [infoDic objectForKey:@"city"];
            debugLog(@"userinfo:%@",infoDic);
//        }else{
//            debugLog(@"返回数据格式不对！");
//        }
    }else{
        if ([self.conversation.ext objectForKey:@"groupSubject"] || [self.conversation.ext objectForKey:@"isPublic"]) {
            //return [self.conversation.ext objectForKey:@"groupSubject"];
            self.nickname = [self.conversation.ext objectForKey:@"groupSubject"];
        }
    }
}

-(void)setInfoByDic:(NSDictionary *)info
{
    if(info){
        debugLog(@"current userinfo:%@",info);
        _nickname = [info objectForKey:@"nickname"];
        if([[info objectForKey:@"pic"] isEqual:[NSNull null]]){
            _pic = @"";
        }else{
            _pic = [info objectForKey:@"pic"];
        }
        _city = [info objectForKey:@"city"];
    }
}
@end
